# -*- coding: UTF-8 -*-
# 作者： 磊
# @Time：2022/5/4
import os
import yaml

def get_object_path():
    return os.getcwd().split('Demo07')[0]

    # 读取extract_yml文件 access_token值的获取
def read_config_yaml(one_node,two_node):
    with open(get_object_path() + "/config.yml", mode='r', encoding='utf-8')as f:
        value = yaml.load(stream=f, Loader=yaml.FullLoader)
        #全部读取是一个json格式的字典
        return value[one_node][two_node]

# 测试读取yaml返回值的类型
# def read_config_yaml1():
#     with open(get_object_path() + "/config.yml", mode='r', encoding='utf-8')as f:
#         value = yaml.load(stream=f, Loader=yaml.FullLoader)
#         print(type(value))

    # 写入extract_yml文件
def write_extract_yaml(data):
    #使用追加的方式写入
    with open(get_object_path() + "/extract.yml", mode='a', encoding='utf-8')as f:
        yaml.dump(data=data, stream=f, allow_unicode=True)

def read_extract_yaml(node_name):
    with open(get_object_path() + "/extract.yml", mode='r', encoding='utf-8')as f:
        value = yaml.load(stream=f, Loader=yaml.FullLoader)
        return value[node_name]


    # 清空
def clear_extract_yaml():
    with open(get_object_path() + "/extract.yml", mode='w', encoding='utf-8')as f:
        f.truncate()

#读取测试用例
def read_testcase_yaml(yaml_path):
    with open(get_object_path() + yaml_path, mode='r', encoding='utf-8')as f:
        value = yaml.load(stream=f, Loader=yaml.FullLoader)
        return value;



if __name__ == '__main__':
      print(get_object_path())
      # print(read_config_yaml1())
      # print(read_config_yaml('base', 'base_gzh_url'))
#     print(read_config_yaml('base', 'base_wyn_url'))
#     print(read_config_yaml('base', 'base_php_url'))
      read_testcase_yaml('/Demo07/testcase/yaml/get_token.yml')



